using System;

namespace Glpt.Data
{
    /// <summary>
    /// 服务器时间类
    /// </summary>
    public class ServerTime
    {
        private static long ServerTimeDiff = 0;//服务器与本机的时间差,服务器-本机的时间
        //private static bool isInit = false;

        /// <summary>
        /// 获取或设置服务器时间
        /// </summary>
        public static DateTime ServerDateTime
        {
            get
            {
                return DateTime.Now.AddTicks(ServerTimeDiff);
            }
            set
            {
                //if (!isInit)
                //{
                //    isInit = true;
                //    Microsoft.Win32.SystemEvents.TimeChanged += new EventHandler(SystemEvents_TimeChanged);
                //}
                ServerTimeDiff = value.Ticks - DateTime.Now.Ticks;
            }
        }

        //系统时间被改变事件处理
        //private static void SystemEvents_TimeChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (BaseInterFace.LoginUserInfo != null)
        //        {
        //            ServerTime.ServerDateTime = new BaseInterFace(0).GetServerTime();
        //        }
        //    }
        //    catch { }
        //}
    }
}
